package configs

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

type ConfigData struct {
	Connection string `yaml: "connection"`
	Name       string `yaml: "name"`
	Cron       string `yaml:"cron"` // 配置作业执行间隔cron
}

/*
sysConfig:
	languo:
		connection: ""
		name: ""
*/

type ConfigItem struct {
	//LanGuo *ConfigData `yaml: "languo"`
	//OpenPlatform *ConfigData `yaml: "openPlatform"`
	Items map[string]*ConfigData `yaml:"database"`
}

type SysConfig struct {
	SysConfig *ConfigItem `yaml:"sysConfig"`
}

func GetConfig() (config *SysConfig) {
	yamlFile, err := ioutil.ReadFile("application.yml")
	if err != nil {
		fmt.Println(err.Error())
	}
	err = yaml.Unmarshal(yamlFile, &config)
	if err != nil {
		fmt.Println(err.Error())
	}
	return config
}
